package com.grom.action;

import java.io.File;
import java.io.IOException;

import com.dispacher.context.ContextHolder;
import com.dispacher.upload.UploadHolder;
import com.grom.excel.ExcelValueBinder;
import com.grom.util.ExcelReader;

public class ImportAction {
	public void gotoImport() {
		ContextHolder.forward("/WEB-INF/jsp/import/update.jsp");
	}

	public void doImport() {
		try {
			String path = ContextHolder.getCurSession().getServletContext()
					.getRealPath("/");
			File file = UploadHolder.saveFileTo(path);
			ExcelReader reader = new ExcelReader(file);
			new ExcelValueBinder(reader.getSheetA(), "A").doBind();
			new ExcelValueBinder(reader.getSheetB(), "B").doBind();
			new ExcelValueBinder(reader.getSheetC(), "C").doBind();
		} catch (IOException e) {
			e.printStackTrace();
		}
		ContextHolder.forward("/WEB-INF/jsp/import/success.jsp");
	}
}
